﻿using Huirui.Cavan.Application.MainBoundedContext.PurchaseModule;
using Huirui.Cavan.Application.MainBoundedContext.StockModule;
using Huirui.Cavan.Application.MainBoundedContext.SystemModule;
using Huirui.Cavan.Domain.MainBoundedContext.PurchaseModule;
using Huirui.Cavan.Domain.MainBoundedContext.StockModule;
using Huirui.Cavan.Domain.MainBoundedContext.SystemModule;
using Huirui.Cavan.Domain.Seedwork;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Domain.MainBoundedContext.ReportModule;
using System.Collections;

namespace Huirui.Cavan.TestAppService
{
    public class TestPayAppService
    {
        private IApplicationContext context;
        private IDepartmentAppService DepartmentAppService;
        private IEmployeeAppService EmployeeAppService;
        private IAccountAppService AccountAppService;
        private IStockInOutTypeAppService StockInOutTypeAppService;
        private ISupplierAppService SupplierAppService;
        private IStockInOutAppService StockInOutAppService;
        private IWareHouseAppService WareHouseAppService;
        private IStockAppService StockAppService;
        private IPurchaseOrderAppService PurchaseOrderAppService;
        private IPayAppService PayAppService;
        private IUnPayAppService UnPayAppService;

        [SetUp]
        public void SetUp()
        {
            context = ContextRegistry.GetContext();
            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
        }

        private void GetAppService()
        {
            this.DepartmentAppService = context.GetObject(SystemModuleConst.DEPARTMENTAPPSERVICE) as IDepartmentAppService;
            this.EmployeeAppService = context.GetObject(SystemModuleConst.EMPLOYEEAPPSERVICE) as IEmployeeAppService;
            this.AccountAppService = context.GetObject(SystemModuleConst.ACCOUNTAPPSERVICE) as IAccountAppService;
            this.StockInOutTypeAppService = context.GetObject(StockModuleConst.STOCKINOUTTYPEAPPSERVICE) as IStockInOutTypeAppService;
            this.SupplierAppService = context.GetObject(SystemModuleConst.SUPPLIERAPPSERVICE) as ISupplierAppService;
            this.StockInOutAppService = context.GetObject(StockModuleConst.STOCKINOUTAPPSERVICE) as IStockInOutAppService;
            this.WareHouseAppService = context.GetObject(StockModuleConst.WAREHOUSEAPPSERVICE) as IWareHouseAppService;
            this.StockAppService = context.GetObject(StockModuleConst.STOCKAPPSERVICE) as IStockAppService;
            this.PayAppService = context.GetObject(PurchaseModuleConst.PAYAPPSERVICE) as IPayAppService;
            this.UnPayAppService = context.GetObject(PurchaseModuleConst.UNPAYAPPSERVICE) as IUnPayAppService;
        }

        [Test]
        public void TestAddPay()
        {
            GetAppService();
            Account account = this.AccountAppService.GetById("001");
            Supplier supplier = this.SupplierAppService.GetById("001_gys001");
            Employee employee = this.EmployeeAppService.GetById("001_e11");

            UnPay unPay1 = this.UnPayAppService.GetById(1);
            IList<UnPay> unPays = new List<UnPay>();
            unPays.Add(unPay1);

            Pay pay = new Pay()
            {
                AccountNumber = "35060342423423",
                Amount = 50,
                Currency = "RMB",
                CurrencyRate = (decimal)1.0,
                Discount = 0,
                FromAccount = account,
                PayDate = DateTime.Now,
                PayEmployee = employee,
                Remark = "test",
                Supplier = supplier
            };

            BoolGenericResult<Pay> result = this.PayAppService.AddOrUpdate(pay);

            Assert.IsNotNull(result);

        }

        [Test]
        public void TestGetUnPayAndPayReport()
        {
            GetAppService();
            IList<UnPayAndPayReport> result = this.PayAppService.GetUnPayAndPayReport(DateTime.Parse("2013-05-01"), DateTime.Parse("2013-05-30"), string.Empty, 10, 1);

            Assert.Greater(result.Count, 0);
        }
    }
}
